"""
子类继承父类后，可以对父类已有的方法给出新的实现，这个动作称之为 《重写》
重写父类方法时，不同的子类会表现出不同的行为，称之为 《多态》
"""


class Person(object):
    def __init__(self, name, age):
        self._name = name
        self._age = age

    @property
    def name(self):
        return self._name

    @property
    def age(self):
        return self._age

    @age.setter
    def age(self, age):
        self._age = age

    def play(self):
        if self._age >= 18:
            print(f'{self._name} is playing games')
        else:
            print(f'{self._name} is studying')


class Student(Person):
    def __init__(self, name, age, grade):
        super().__init__(name, age)
        self._grade = grade

    @property
    def grade(self):
        return self._grade

    @grade.setter
    def grade(self, grade):
        self._grade = grade

    def play(self):
        super().play()


class Teacher(Person):
    def __init__(self, name, age, title):
        super().__init__(name, age)
        self._title = title

    @property
    def title(self):
        return self._title

    @title.setter
    def title(self, title):
        self._title = title

    def play(self):
        print('The teacher is teaching %s' % self._title)


def main():
    stu = Student('Ben', 19, 3)
    stu.play()

    tt = Teacher('Tan', 59, 'English')
    tt.play()


if __name__ == '__main__':
    main()
